package com.example.translateappjava.Service.MedicalAtlas;

import android.app.Activity;

public class MedicalAtlasHelper {
    /**
     * 这里是在fragment里面的调用，在其他地方调用时，将getActivity换成对应的activity即可
     * 实现医疗图谱的调用
     */
//    MedicalAtlasListener medicalAtlasListener = (MedicalAtlasListener) getActivity();
//    MedicalAtlasHelper medicalAtlasHelper = new MedicalAtlasHelper(getActivity());
//        medicalAtlasHelper.setMedicalAtlasListener(medicalAtlasListener);
//        medicalAtlasHelper.MedicalAtlasRequest("艾滋病");

    private Activity activity;
    private MedicalAtlasListener medicalAtlasListener;


    public MedicalAtlasHelper(Activity activity){
        this.activity = activity;
    }
    public void setMedicalAtlasListener(MedicalAtlasListener listener){
        this.medicalAtlasListener = listener;
    }

    public interface MedicalAtlasListener{
        void onMedicalAtlasResponse(String response);
    }

    public void MedicalAtlasRequest(String message){
        new Thread(new Runnable() {
            @Override
            public void run() {
                String response = getMedicalAtlasResponse(message);
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (medicalAtlasListener != null) {
                            medicalAtlasListener.onMedicalAtlasResponse(response);
                        }
                    }
                });
            }
        }).start();
    }

    private String getMedicalAtlasResponse(String message){
        MedicalAtlasImplication medicalAtlasImplication = new MedicalAtlasImplication();
        return medicalAtlasImplication.getMedicalAtlasResult(message);
    }

}
